import type { RentBuilding, EnterpriseDetail, EnterpriseListData, EnterpriseListParams, EnterpriseParams, Industry, RentParams, Datum } from "@/types/enterprise"
import service, { myRequest } from "@/utils/reuqest";

// 获取企业列表
export const getEnterpriseListApi = (params: EnterpriseListParams) => {
    return myRequest<EnterpriseListData>('/park/enterprise', 'get', params)
}

// 请求行业列表
export const getIndustryListAPI = () => {
    return myRequest<Industry[]>('/park/industry', 'GET')
}

/**
 * 创建公司
 * @param {*} data
 * @returns
 */
export const createEnterpriseAPI = (data: EnterpriseParams) =>{
    return myRequest('/park/enterprise', 'POST', data)
}

// 查看公司
export const watchEnterpriseAPI = (id: number) => {
    return myRequest<EnterpriseDetail>(`/park/enterprise/${id}`, 'GET')
}

// 编辑公司
export const editEnterpriseAPI = (id: number, data: EnterpriseParams) => {
    return myRequest(`/park/enterprise`, 'PUT', { ...data, id })
}

// 删除公司
export const deleteEnterpriseAPI = (id: number) => {
    return myRequest(`/park/enterprise/${id}`, 'DELETE')
}

// 获取可租dai楼宇列表
export const getRentBuildingListAPI = () => {
    return myRequest<RentBuilding[]>('/park/rent/building', 'GET')
}

// 添加/续费租赁
export const  createRentAPI = (data: RentParams) => {
    return myRequest('/park/enterprise/rent', 'POST', data)
}
// 获取租贷列表
export const getRentListAPI = (id: number) => {
    return myRequest<Datum[]>(`/park/enterprise/rent/${id}`, 'GET')
}
// 删除租赁
export const deleteRentItemAPI = (id: string) => {
    return myRequest(`/park/enterprise/rent/${id}`, 'DELETE')
}
// 退租
export const outRentItemAPI = (id: string) => {
    return myRequest(`/park/enterprise/rent/${id}`, 'PUT')
}

/**
 * 获取企业详情
 * @param {*} id
 * @returns
 */
export const getEnterpriseDetailAPI = (id: string) => {
    return myRequest<EnterpriseDetail>(`/park/enterprise/${id}`, 'GET')
}

/**
 * 下载合同文件
 */
export const downloadContract = (id: number) => {
    return service<null, Blob>({
      url: `/download/${id}`,
      method: 'GET',
      responseType: 'blob' // axios 会把响应的文件流格式化成 Blob 数据块对象
    })
}